/*
 * Copyright 2011 yura.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.opu.db_vdumper.util.monitors;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

/**
 *
 * @author yura
 */
public class DoubleProgresMonitorImpl extends SimpleProgresMonitorImpl
        implements DoubleProgresMonitor {

    private JProgressBar lowBar;
    private JLabel lowNoteLbl;
    private boolean indeterminate = false;

    public DoubleProgresMonitorImpl(String message) {
        super(message);
    }

    public DoubleProgresMonitorImpl(JFrame parent, String msg) {
        super(parent, msg);
    }

    @Override
    protected Object[] getContentData() {
        lowBar = new JProgressBar();
        lowBar.setStringPainted(true);
        lowBar.setMinimum(MIN);
        lowBar.setMaximum(MAX);

        lowNoteLbl = new JLabel();
        lowNoteLbl.setLabelFor(this);

        Object[] data = super.getContentData();
        Object[] newData = new Object[data.length + 2];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = lowNoteLbl;
        newData[data.length + 1] = lowBar;
        
        return newData;
    }

    @Override
    public void showLowBar(boolean value){
        lowBar.setVisible(value);
        lowNoteLbl.setVisible(value);
    }

    @Override
    public void setLowBarIndeterminate(boolean value) {
        lowBar.setStringPainted(value);
        lowBar.setIndeterminate(value);
        indeterminate = value;
    }

    @Override
    public void setLowBarNoteAndProgress(String note, int prog) {
        setNote(note);
        setProgress(prog);
    }

    @Override
    public void setLowBarNote(String note) {
        lowNoteLbl.setText(note);
    }

    @Override
    public void setLowBarProgress(int prog) {
        if (!indeterminate) {
            lowBar.setValue(prog);
        }
    }

}
